Skip to content

wasm: lazily initialize tls.std, add configuration macro for assert logging#7

Merged
tspader merged 1 commit into
mainfrom
wasm/fix-unconditional-wasi-imports
Jun 9, 2026
Merged

wasm: lazily initialize tls.std, add configuration macro for assert logging#7
tspader merged 1 commit into
mainfrom
wasm/fix-unconditional-wasi-imports

Conversation

@tspader

@tspader tspader commented Jun 9, 2026

Copy link
Copy Markdown
Owner

sp_assert_f unconditionally logged a nice message when triggered. This, however, forced WASM builds to pull in fd_write. In the browser, this forces you to shim fd_write with no recourse, even if you don't want the logging.

Added a macro to configure what happens on assert (nothing, trap only, trap and log). I decided against a higher level configuration (like SP_NO_IO); it's a little unintuitive that, if you were to pull in sp.h for such a WASM thing, that it defaults to wanting fd_write and the configuration to turn that off is hidden in the configuration for assert. Fairly unintuitive.

But sp_assert_f() is legitimately the only place that the library writes output. It's a standard library. It SHOULDN'T log during normal use. Presenting a macro framed as "make this library log" is equally confusing. I also considered defaulting to trap only on WASM, but that degrades the equally common case of running a WASM program inside a preview1 enabled environment.

…ogging

sp_assert_f unconditionally logged a nice message when triggered. This,
however, forced WASM builds to pull in fd_write. In the browser, this
forces you to shim fd_write with no recourse, even if you don't want the
logging.

Added a macro to configure what happens on assert (nothing, trap only,
trap and log). I decided against a higher level configuration (like
SP_NO_IO); it's a little unintuitive that, if you were to pull in sp.h
for such a WASM thing, that it defaults to wanting fd_write and the
configuration to turn that off is hidden in the configuration for
assert. Fairly unintuitive.

But sp_assert_f() is legitimately the only place that the library writes
output. It's a standard library. It SHOULDN'T log during normal use.
Presenting a macro framed as "make this library log" is equally
confusing. I also considered defaulting to trap only on WASM, but that
degrades the equally common case of running a WASM program inside a
preview1 enabled environment.
@tspader tspader merged commit 9cdf758 into main Jun 9, 2026
15 checks passed
@tspader tspader deleted the wasm/fix-unconditional-wasi-imports branch June 9, 2026 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant